﻿Imports System.IO
Imports System.Text
Imports System.Collections.ObjectModel
Imports System.Xml
Imports System.Text.RegularExpressions

Public Class frmFolderPad
    Private _IsAvailable As Boolean = False

    Public ReadOnly Property IsAvailable() As Boolean
        Get
            Return _IsAvailable
        End Get
    End Property

#Region "Declarations"

    Private Enum BrowseMethod
        Find
        Custom
    End Enum

    Public dtFolderList As New DataTable
    Dim tsbtnCollection As New Collection(Of ToolStripButton)
    Dim FoldersXML As New String(savePath & "folders.xml")


    'Overrides
    Protected Overrides Sub WndProc(ByRef m As Message)
        ' Listen for operating system messages
        Select Case m.Msg
            Case WM_WINDOWPOSCHANGING
                SnapToDesktopBorder(Me, m.LParam, 0)
        End Select
        MyBase.WndProc(m)
    End Sub
#End Region

#Region "FolderPad"
    Private Sub frmFolderPad_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim bmp As Bitmap = My.Resources.Pad_FolderPad
        Me.Icon = Icon.FromHandle(bmp.GetHicon)

        Me.Location = My.Settings.FolderPadLocation
        Me.Size = My.Settings.FolderPadSize

        Select Case My.Settings.ToolstripLocation
            Case 0
                FolderPad.tsSystemLocations.Dock = DockStyle.Left
                FolderPad.tsSystemLocations.LayoutStyle = ToolStripLayoutStyle.VerticalStackWithOverflow
            Case 1
                FolderPad.tsSystemLocations.Dock = DockStyle.Top
                FolderPad.tsSystemLocations.LayoutStyle = ToolStripLayoutStyle.HorizontalStackWithOverflow
            Case 2
                FolderPad.tsSystemLocations.Dock = DockStyle.Bottom
                FolderPad.tsSystemLocations.LayoutStyle = ToolStripLayoutStyle.HorizontalStackWithOverflow
        End Select

        If My.Settings.ToolstripShow = 1 Then
            reorderButtons()
        ElseIf My.Settings.ToolstripShow = 0 Then
            tsSystemLocations.Visible = False
        End If

        dtFolderList.Columns.Add("id")
        dtFolderList.Columns.Add("lbl")
        dtFolderList.Columns.Add("abs")
        dtFolderList.Columns.Add("unc")
        dtFolderList.Columns.Add("tag")

        If My.Settings.FolderPadLabelList Is Nothing Then
            My.Settings.FolderPadLabelList = New System.Collections.Specialized.StringCollection
        End If

        If System.IO.File.Exists(savePath & "folders.xml") Then
            XML_Read()
            RemoveHandler lstLabels.SelectedIndexChanged, AddressOf lstLabels_SelectedIndexChanged
            populateListBox()
            AddHandler lstLabels.SelectedIndexChanged, AddressOf lstLabels_SelectedIndexChanged
        End If

        loadTagList()
        CheckButtons()
        _IsAvailable = True
    End Sub

    Private Sub frmFolderPad_Move(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Move
        My.Settings.FolderPadLocation = Me.Location
        My.Settings.Save()
    End Sub

    Private Sub frmFolderPad_ResizeEnd(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.ResizeEnd
        My.Settings.FolderPadSize = Me.Size
        My.Settings.Save()
    End Sub

    Private Sub frmFolderPad_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        If e.CloseReason <> CloseReason.WindowsShutDown Then
            e.Cancel = True
            Me.Hide()
        End If
    End Sub
#End Region

#Region "SubProcedures"
    Public Sub XML_Read()
        Try
            dtFolderList.Rows.Clear()
            Dim xml_doc As XDocument = XDocument.Parse(IO.File.ReadAllText(savePath & "folders.xml"))

            'Where xe.Attribute("tag").Value = "default" _
            Dim result = From xe In xml_doc.Descendants.Elements("folder") _
                Select New With { _
                    .id = xe.Attribute("id").Value, _
                    .lbl = xe.Attribute("lbl").Value, _
                    .abs = xe.Attribute("abs").Value, _
                    .unc = xe.Attribute("unc").Value, _
                    .tag = xe.Attribute("tag").Value _
                }

            Dim i As Integer = 0
            For Each attributes In result
                dtFolderList.Rows.Add(attributes.id.ToString(), attributes.lbl.ToString(), attributes.abs.ToString(), attributes.unc.ToString(), attributes.tag.ToString())
            Next
        Catch ex As Exception
            MessageBox.Show(ex.ToString())
        End Try
    End Sub

    Public Sub XML_Write()
        Try
            Dim xmlWriter As XmlTextWriter = New XmlTextWriter(savePath & "folders.xml", System.Text.Encoding.UTF8)
            xmlWriter.Formatting = Formatting.Indented
            xmlWriter.WriteStartElement("folder_list")
            Dim i As Integer = 0

            For Each info As DataRow In dtFolderList.Rows
                xmlWriter.WriteStartElement("folder")

                xmlWriter.WriteStartAttribute("id")
                xmlWriter.WriteString(CType(i, String))
                xmlWriter.WriteEndAttribute()

                xmlWriter.WriteStartAttribute("lbl")
                xmlWriter.WriteString(info("lbl").ToString)
                xmlWriter.WriteEndAttribute()

                xmlWriter.WriteStartAttribute("abs")
                xmlWriter.WriteString(info("abs"))
                xmlWriter.WriteEndAttribute()

                xmlWriter.WriteStartAttribute("unc")
                xmlWriter.WriteString(info("unc"))
                xmlWriter.WriteEndAttribute()

                xmlWriter.WriteStartAttribute("tag")
                xmlWriter.WriteString(info("tag"))
                xmlWriter.WriteEndAttribute()

                xmlWriter.WriteEndElement()

                i += 1
            Next info

            xmlWriter.WriteEndElement()
            xmlWriter.Close()
        Catch ex As Exception
            MessageBox.Show(ex.ToString())
        End Try
    End Sub

    Public Sub loadTagList()
        cboTags.Items.Clear()
        cboTags.Items.Add("All")
        If Not My.Settings.FolderPadLabelList Is Nothing Then
            For Each filter As String In My.Settings.FolderPadLabelList
                cboTags.Items.Add(filter)
            Next
        End If
        cboTags.SelectedIndex = 0
    End Sub

    Public Sub populateListBox()
        If cboTags.Text = "All" Then
            dtFolderList.DefaultView.RowFilter = String.Empty
            lstLabels.DataSource = dtFolderList.DefaultView
            lstLabels.DisplayMember = "lbl"
            lstLabels.ValueMember = "id"
        Else
            dtFolderList.DefaultView.RowFilter = String.Format("tag = '{0}'", cboTags.Text)
            lstLabels.DataSource = dtFolderList.DefaultView
            lstLabels.DisplayMember = "lbl"
            lstLabels.ValueMember = "id"
        End If

        lstLabels.Focus()
        If lstLabels.Items.Count > 0 Then
            lstLabels.SelectedIndex = 0
        End If
    End Sub

    Private Sub AccessFolder()
        If lstLabels.SelectedItems.Count <> 0 Then
            Try
                ExistsAltap()
                With My.Settings
                    Dim pathString As String = ""

                    If lstLabels.Items.Count <> 0 Or lstLabels.SelectedIndex <> -1 Then
                        Dim i As Integer = CType(lstLabels.SelectedValue, Integer)

                        If My.Settings.uncEnabled = 0 Then
                            pathString = dtFolderList.Rows(i).Item("abs")
                        ElseIf My.Settings.uncEnabled = 1 Then
                            pathString = dtFolderList.Rows(i).Item("unc")
                        End If

                        If .ExplorerDefault = 0 Then
                            Process.Start(pathString)
                        ElseIf .ExplorerDefault = 1 Then
                            If .ExplorerShift = 0 Then
                                buildExplorer(pathString)
                            ElseIf .ExplorerShift = 1 And Control.ModifierKeys = Keys.Shift Then
                                buildExplorer(pathString)
                            Else
                                Process.Start(pathString)
                            End If
                        End If

                        FolderPad.Hide()
                    End If
                End With
            Catch ex As Exception
                MessageBox.Show("Something is preventing the folder from being accessed." & vbNewLine & "Please check your system settings or contact your System Administrator.", "System Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try
        End If
    End Sub

    Private Sub buildExplorer(ByVal pathString As String)
        With My.Settings
            Dim param As New StringBuilder

            Select Case .AltapWindow
                Case 0
                    param.Append("-L " & pathString)
                Case 1
                    param.Append("-R" & pathString)
            End Select

            param.Append(" -I " & .AltapIconColor)
            If .AltapTitlebarPrefix.Length <> 0 Then
                param.Append(" -T " & .AltapTitlebarPrefix)
            Else
                param.Append(" -T " & """""")
            End If
            Process.Start(.ExplorerLocation & "\salamand.exe", param.ToString)
        End With
    End Sub

    Private Sub browseFolders(ByVal method As BrowseMethod)
        RemoveHandler lstLabels.SelectedIndexChanged, AddressOf lstLabels_SelectedIndexChanged

        Dim row As DataRow = dtFolderList.Rows.Add("", "", "", "")
        Dim ip As New frmItemProperties(row)
        Dim TagsSelectedIndex As Integer = cboTags.SelectedIndex

        If cboTags.Text <> "All" Then
            ip.cboTags.Text = cboTags.Text
        End If

        Select Case method
            Case BrowseMethod.Find
                If FolderBrowseDiag.ShowDialog() = Windows.Forms.DialogResult.OK Then
                    ip.Text = "Add New Folder"
                    ip.txtPath.Text = FolderBrowseDiag.SelectedPath
                    ip.ShowDialog()
                Else
                    row.Delete()
                    Exit Sub
                End If
            Case BrowseMethod.Custom
                ip.Text = "Add New Folder (Custom)"
                ip.txtPath.Properties.ReadOnly = False
                ip.ShowDialog()
        End Select

        If ip.DialogResult = DialogResult.OK Then
            XML_Write()
            XML_Read()
            populateListBox()
            loadTagList()
            cboTags.SelectedIndex = TagsSelectedIndex
        ElseIf ip.DialogResult = DialogResult.Cancel Then
            dtFolderList.Rows.Remove(row)
        End If

        AddHandler lstLabels.SelectedIndexChanged, AddressOf lstLabels_SelectedIndexChanged
    End Sub

    Private Sub CheckButtons()
        If lstLabels.Items.Count = 0 Then
            tsbtnUp.Enabled = False
            tsbtnDown.Enabled = False
        End If

        If lstLabels.SelectedIndex = 0 Then
            tsbtnUp.Enabled = False
        Else
            tsbtnUp.Enabled = True
        End If

        If lstLabels.SelectedIndex = lstLabels.Items.Count - 1 Then
            tsbtnDown.Enabled = False
        Else
            tsbtnDown.Enabled = True
        End If

        If cboTags.SelectedIndex > 0 Then
            tsbtnUp.Enabled = False
            tsbtnDown.Enabled = False
        End If
    End Sub

    Private Sub checkMenuStatus()
        If lstLabels.SelectedIndex = -1 Then
            mnuOpen.Enabled = False
            mnuRemove.Enabled = False
            mnuEdit.Enabled = False
            mnuCopyPath.Enabled = False
        Else
            mnuOpen.Enabled = True
            mnuRemove.Enabled = True
            mnuEdit.Enabled = True
            mnuCopyPath.Enabled = True
        End If
    End Sub

    Private Sub launchUtilities(ByVal utility As String, Optional ByVal param As String = "")
        Try
            Process.Start(utility, param)
            FolderPad.Hide()
        Catch ex As Exception
            MessageBox.Show("This utility could not be launched because it does not exist or could not be found.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

    Private Sub EditSelectedItem()
        Dim TagsSelectedIndex As Integer = cboTags.SelectedIndex

        Dim ip As New frmItemProperties(dtFolderList.Rows(lstLabels.SelectedValue))

        If cboTags.Text <> "All" Then
            ip.cboTags.Text = cboTags.Text
        End If

        ip.Text = "Edit Folder Properties"
        ip.txtPath.Properties.ReadOnly = False

        ip.txtPath.Text = dtFolderList.Rows(lstLabels.SelectedValue).Item("abs")
        ip.txtLabel.Text = dtFolderList.Rows(lstLabels.SelectedValue).Item("lbl")
        ip.cboTags.Text = dtFolderList.Rows(lstLabels.SelectedValue).Item("tag")

        ip.ShowDialog()
        If ip.DialogResult = DialogResult.OK Then
            XML_Write()
            populateListBox()
            loadTagList()
            cboTags.SelectedIndex = TagsSelectedIndex
        End If
    End Sub

    Private Sub dxbeFilter_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles dxbeFilter.KeyUp
        If e.KeyCode = Keys.Up Then
            If lstLabels.SelectedIndex <> 0 Then
                lstLabels.SelectedIndex = lstLabels.SelectedIndex - 1
            End If
        End If

        If e.KeyCode = Keys.Down Then
            If lstLabels.SelectedIndex <> lstLabels.Items.Count - 1 Then
                lstLabels.SelectedIndex = lstLabels.SelectedIndex + 1
            End If
        End If

        If e.KeyCode = Keys.F2 And lstLabels.SelectedItems.Count <> 0 Then
            EditSelectedItem()
        End If
    End Sub

    Private Sub dxbeFilter_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles dxbeFilter.KeyPress
        Dim allowedChars As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_+-=&!@#$%&(){}|\:;<>,.?/" + vbBack + Chr(Keys.Space) + Chr(Keys.Delete)

        If allowedChars.IndexOf(e.KeyChar) = -1 Then
            e.Handled = True
        End If
    End Sub

#End Region

#Region "lstLabels"
    Private Sub lstLabels_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstLabels.DoubleClick
        AccessFolder()
    End Sub

    Private Sub lstLabels_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles lstLabels.KeyDown
        If e.KeyCode = Keys.Enter Then
            AccessFolder()
        End If
    End Sub

    Private Sub lstLabels_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstLabels.SelectedIndexChanged
        CheckButtons()

        If lstLabels.SelectedIndex <> -1 Then
            Dim i As Integer = CType(lstLabels.SelectedValue, Integer)

            If My.Settings.uncEnabled = 0 Then
                lblPath.Text = dtFolderList.Rows(i).Item("abs")
            ElseIf My.Settings.uncEnabled = 1 Then
                lblPath.Text = dtFolderList.Rows(i).Item("unc")
            End If
        Else
            lblPath.Text = String.Empty
        End If
    End Sub

    Private Sub lstLabels_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles lstLabels.DragDrop
        RemoveHandler lstLabels.SelectedIndexChanged, AddressOf lstLabels_SelectedIndexChanged

        If e.Data.GetDataPresent(DataFormats.FileDrop) Then
            Dim filePaths As String() = CType(e.Data.GetData(DataFormats.FileDrop), String())
            If (IO.File.GetAttributes(filePaths(0)) And IO.FileAttributes.Directory) = IO.FileAttributes.Directory Then
                Dim pathString As String = filePaths(0)

                Dim row As DataRow = dtFolderList.Rows.Add("", "", "", "")
                Dim ip As New frmItemProperties(row)
                Dim TagsSelectedIndex As Integer = cboTags.SelectedIndex

                If cboTags.Text <> "All" Then
                    ip.cboTags.Text = cboTags.Text
                End If

                ip.Text = "Add New Folder"
                ip.txtPath.Text = pathString
                ip.ShowDialog()

                If ip.DialogResult = DialogResult.OK Then
                    XML_Write()
                    XML_Read()

                    populateListBox()
                    loadTagList()
                    cboTags.SelectedIndex = TagsSelectedIndex
                ElseIf ip.DialogResult = DialogResult.Cancel Then
                    dtFolderList.Rows.Remove(row)
                End If
            End If
        End If

        AddHandler lstLabels.SelectedIndexChanged, AddressOf lstLabels_SelectedIndexChanged
    End Sub

    Private Sub lstLabels_DragEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles lstLabels.DragEnter
        If e.Data.GetDataPresent(DataFormats.FileDrop) Then
            Dim filePaths As String() = CType(e.Data.GetData(DataFormats.FileDrop), String())
            If filePaths.Count = 1 Then
                If (IO.File.GetAttributes(filePaths(0)) And IO.FileAttributes.Directory) = IO.FileAttributes.Directory Then
                    e.Effect = DragDropEffects.Copy
                End If
            End If
        End If
    End Sub

    Private Sub lstLabels_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lstLabels.MouseDown
        Dim lb As ListBox = CType(sender, ListBox)
        Dim pt As New Point(e.X, e.Y)
        Dim index As Integer = lb.IndexFromPoint(pt)

        If e.Button = MouseButtons.Right Then
            If index >= 0 Then
                lstLabels.SelectedItem = lstLabels.Items.Item(index)
            ElseIf index = -1 Then
                lstLabels.ClearSelected()
                lblPath.Text = ""
            End If
            checkMenuStatus()
        End If

        If e.Button = MouseButtons.Left Then
            If index = -1 Then
                lstLabels.ClearSelected()
                lblPath.Text = ""
            End If
        End If
    End Sub

    Private Sub cboTags_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboTags.SelectedIndexChanged
        populateListBox()
        dxbeFilter.Text = String.Empty
        CheckButtons()
    End Sub

    Private Sub dxbeFilter_EditValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dxbeFilter.EditValueChanged
        If dxbeFilter.Text <> "" Then
            dtFolderList.DefaultView.RowFilter = String.Format("lbl LIKE '*{0}*'", dxbeFilter.Text)
            dtFolderList.DefaultView.Sort = "id ASC"
            lstLabels.DataSource = dtFolderList.DefaultView
            lstLabels.ValueMember = "id"
            lstLabels.DisplayMember = "lbl"
        ElseIf dxbeFilter.Text = "" Then
            dtFolderList.DefaultView.Sort = String.Empty
            populateListBox()
            dxbeFilter.Focus()
        End If

        If lstLabels.Items.Count > 0 Then
            lstLabels.SelectedIndex = 0
        End If
    End Sub

    Private Sub dxbeFilter_ButtonPressed(ByVal sender As System.Object, ByVal e As DevExpress.XtraEditors.Controls.ButtonPressedEventArgs) Handles dxbeFilter.ButtonPressed
        dxbeFilter.Text = ""
        dtFolderList.DefaultView.Sort = String.Empty
        populateListBox()
    End Sub

    Private Sub dxbeFilter_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles dxbeFilter.KeyDown
        If e.KeyCode = Keys.Enter Then
            AccessFolder()
        End If
    End Sub
#End Region

#Region "Menus"
    Private Sub mnuOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuOpen.Click
        AccessFolder()
    End Sub

    Private Sub mnuAddMapped_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuAddMapped.Click
        browseFolders(BrowseMethod.Find)
    End Sub

    Private Sub mnuAddCustom_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuAddCustom.Click
        browseFolders(BrowseMethod.Custom)
    End Sub
    Private Sub mnuRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuRemove.Click
        If MessageBox.Show("Are you sure you want to remove: " & lstLabels.Text & "?", "Removing Entry", MessageBoxButtons.YesNo, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button2) = Windows.Forms.DialogResult.Yes And lstLabels.SelectedIndex <> -1 Then
            dtFolderList.Rows.RemoveAt(lstLabels.SelectedValue)

            XML_Write()
            XML_Read()

            If cboTags.Text <> "All" Then
                populateListBox()
            Else
                populateListBox()
            End If

            CheckButtons()
        End If
    End Sub

    Private Sub mnuEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuEdit.Click
        EditSelectedItem()
    End Sub

    Private Sub mnuCopyPath_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuCopyPath.Click
        Dim selectedItem As Integer = lstLabels.SelectedIndex

        Dim i As Integer = CType(lstLabels.SelectedValue, Integer)

        If My.Settings.uncEnabled = 0 Then
            Clipboard.SetText(dtFolderList.Rows(i).Item("abs"))
        ElseIf My.Settings.uncEnabled = 1 Then
            Clipboard.SetText(dtFolderList.Rows(i).Item("unc"))
        End If
    End Sub
#End Region

#Region "ToolStrip Buttons"
    Private Sub tsbtnUp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbtnUp.Click
        If lstLabels.SelectedIndex <> -1 Then
            Dim i As Integer = CType(lstLabels.SelectedValue, Integer)

            Dim tempRow As DataRow = dtFolderList.NewRow
            tempRow.ItemArray = dtFolderList.Rows(i).ItemArray
            dtFolderList.Rows.RemoveAt(i)
            dtFolderList.Rows.InsertAt(tempRow, i - 1)

            XML_Write()
            XML_Read()
            populateListBox()

            lstLabels.ClearSelected()
            lstLabels.SelectedIndex = i - 1
            CheckButtons()
        End If
    End Sub

    Private Sub tsbtnDown_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbtnDown.Click
        If lstLabels.SelectedIndex <> -1 Then
            Dim i As Integer = CType(lstLabels.SelectedValue, Integer)

            Dim tempRow As DataRow = dtFolderList.NewRow
            tempRow.ItemArray = dtFolderList.Rows(i).ItemArray
            dtFolderList.Rows.RemoveAt(i)
            dtFolderList.Rows.InsertAt(tempRow, i + 1)

            XML_Write()
            XML_Read()
            populateListBox()

            lstLabels.ClearSelected()
            lstLabels.SelectedIndex = i + 1
            CheckButtons()
        End If
    End Sub

    Public Sub reorderButtons()
        For Each tsButton As ToolStripButton In tsSystemLocations.Items
            tsbtnCollection.Add(CType(tsButton, ToolStripButton))
        Next
        tsSystemLocations.Items.Clear()

        If My.Settings.SystemLocationsOrder IsNot Nothing AndAlso My.Settings.SystemLocationsOrder.Count > 0 Then
            For Each o As Object In My.Settings.SystemLocationsOrder
                Select Case o.ToString
                    Case "Add Hardware Wizard"
                        tsSystemLocations.Items.Add(tsbtnCollection(1))
                    Case "Add/Remove Programs"
                        tsSystemLocations.Items.Add(tsbtnCollection(2))
                    Case "Administrative Tools"
                        tsSystemLocations.Items.Add(tsbtnCollection(3))
                    Case "Certificate Manager"
                        tsSystemLocations.Items.Add(tsbtnCollection(4))
                    Case "Character Map"
                        tsSystemLocations.Items.Add(tsbtnCollection(5))
                    Case "Command Prompt"
                        tsSystemLocations.Items.Add(tsbtnCollection(6))
                    Case "Computer"
                        tsSystemLocations.Items.Add(tsbtnCollection(7))
                    Case "Computer Management"
                        tsSystemLocations.Items.Add(tsbtnCollection(8))
                    Case "Control Panel"
                        tsSystemLocations.Items.Add(tsbtnCollection(9))
                    Case "Disk Defragment"
                        tsSystemLocations.Items.Add(tsbtnCollection(10))
                    Case "Network Properties"
                        tsSystemLocations.Items.Add(tsbtnCollection(11))
                    Case "Printers"
                        tsSystemLocations.Items.Add(tsbtnCollection(12))
                    Case "Registry Editor"
                        tsSystemLocations.Items.Add(tsbtnCollection(13))
                    Case "Remote Desktop"
                        tsSystemLocations.Items.Add(tsbtnCollection(14))
                    Case "Scheduled Tasks"
                        tsSystemLocations.Items.Add(tsbtnCollection(15))
                    Case "Security Center"
                        tsSystemLocations.Items.Add(tsbtnCollection(16))
                    Case "System Configuration Editor"
                        tsSystemLocations.Items.Add(tsbtnCollection(17))
                    Case "System Configuration Utility"
                        tsSystemLocations.Items.Add(tsbtnCollection(18))
                    Case "System Information"
                        tsSystemLocations.Items.Add(tsbtnCollection(19))
                    Case "System Properties"
                        tsSystemLocations.Items.Add(tsbtnCollection(20))
                    Case "Task Manager"
                        tsSystemLocations.Items.Add(tsbtnCollection(21))
                End Select
            Next
        Else
            tsSystemLocations.Items.Add(tsbtnCollection(0)) 'Add
        End If
    End Sub

    Private Sub tsbtnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbtnAdd.Click
        Dim Settings As New frmSettings
        Settings.Show()

        Settings.Panels.Item(3).Visible = True
        Settings.Panels.Item(3).BringToFront()
        Me.Hide()
    End Sub

    Private Sub tsbtnAddHardwareWizard_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbtnAddHardwareWizard.Click
        launchUtilities("hdwwiz.cpl")
    End Sub

    Private Sub tsbtnAddRemovePrograms_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbtnAddRemovePrograms.Click
        launchUtilities("appwiz.cpl")
    End Sub

    Private Sub tsbtnAdministrativeTools_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbtnAdministrativeTools.Click
        launchUtilities("control.exe", "admintools")
    End Sub

    Private Sub tsbtnCertificateManager_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbtnCertificateManager.Click
        launchUtilities("certmgr.msc")
    End Sub

    Private Sub tsbtnCharacterMap_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbtnCharacterMap.Click
        launchUtilities("charmap.exe")
    End Sub

    Private Sub tsbtnCommandPrompt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbtnCommandPrompt.Click
        Dim startInfo = New ProcessStartInfo()
        Dim p As New Process

        startInfo.UseShellExecute = True
        startInfo.WorkingDirectory = "C:\"
        startInfo.FileName = "cmd.exe"
        If MessageBox.Show("Elevate Command Prompt as Administrator?", "Elevation Optional", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
            startInfo.Verb = "runas"
        End If

        Try
            p = Process.Start(startInfo)

            FolderPad.Hide()
        Catch ex As Exception
            MessageBox.Show("This utility could not be launched because it does not exist or could not be found.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

    Private Sub tsbtnComputer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbtnComputer.Click
        launchUtilities("::{20D04FE0-3AEA-1069-A2D8-08002B30309D}")
    End Sub

    Private Sub tsbtnComputerManagement_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbtnComputerManagement.Click
        launchUtilities("compmgmt.msc")
    End Sub

    Private Sub tsbtnControlPanel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbtnControlPanel.Click
        launchUtilities("control.exe")
    End Sub

    Private Sub tsbtnDiskDefragment_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbtnDiskDefragment.Click
        Select Case wVersion.versionName
            Case "XP"
                launchUtilities("dfrg.msc")
            Case "Vista", "Seven"
                launchUtilities("dfrgui.exe")
        End Select
    End Sub

    Private Sub tsbtnNetworkProperties_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbtnNetworkProperties.Click
        launchUtilities("ncpa.cpl")
    End Sub

    Private Sub tsbtnPrinters_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbtnPrinters.Click
        launchUtilities("rundll32.exe", "shell32.dll,SHHelpShortcuts_RunDLL PrintersFolder")
    End Sub

    Private Sub tsbtnRegistryEditor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbtnRegistryEditor.Click
        Select Case wVersion.versionName
            Case "XP"
                launchUtilities("regedit.exe")
            Case "Vista", "Seven"
                launchUtilities("regedt32.exe")
        End Select
    End Sub

    Private Sub tsbtnRemoteDesktop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbtnRemoteDesktop.Click
        launchUtilities("mstsc.exe")
    End Sub

    Private Sub tsbtnScheduledTasks_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbtnScheduledTasks.Click
        launchUtilities("control.exe", "schedtasks")
    End Sub

    Private Sub tsbtnSecurityCenter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbtnSecurityCenter.Click
        launchUtilities("wscui.cpl")
    End Sub

    Private Sub tsbtnSystemConfigurationEditor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbtnSystemConfigurationEditor.Click
        launchUtilities("sysedit.exe")
    End Sub

    Private Sub tsbtnSystemConfigurationUtility_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbtnSystemConfigurationUtility.Click
        launchUtilities("msconfig.exe")
    End Sub

    Private Sub tsbtnSystemInformation_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbtnSystemInformation.Click
        launchUtilities("msinfo32.exe")
    End Sub

    Private Sub tsbtnSystemProperties_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbtnSystemProperties.Click
        launchUtilities("sysdm.cpl")
    End Sub

    Private Sub tsbtnTaskManager_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbtnTaskManager.Click
        launchUtilities("taskmgr.exe")
    End Sub
#End Region

    '' Possible Code to allow reorder of entries by Drag and Drop
    ''
    ''
    'Private Sub lstLabels_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lstLabels.MouseMove
    '    Dim lb As ListBox = CType(sender, ListBox)
    '    Dim pt As New Point(e.X, e.Y)
    '    Dim index As Integer = lb.IndexFromPoint(pt)

    '    If index <> -1 Then
    '        If My.Settings.uncEnabled = 0 Then
    '            lblPath.Text = dtFolderList.Rows(index).Item("abs")
    '        ElseIf My.Settings.uncEnabled = 1 Then
    '            lblPath.Text = dtFolderList.Rows(index).Item("unc")
    '        End If
    '    Else
    '        If lstLabels.SelectedIndex <> -1 Then
    '            If My.Settings.uncEnabled = 0 Then
    '                lblPath.Text = dtFolderList.Rows(lstLabels.SelectedIndex).Item("abs")
    '            ElseIf My.Settings.uncEnabled = 1 Then
    '                lblPath.Text = dtFolderList.Rows(lstLabels.SelectedIndex).Item("unc")
    '            End If
    '        Else
    '            lblPath.Text = String.Empty
    '        End If
    '    End If
    'End Sub

End Class